<?php

namespace Entity;

class Domain extends \Home {

	public $www;

	public $admin;

	public $wap;

	public $api;

    public $statistics;

    public $baiduMap;

	public function __construct() {
		$serverName = $_SERVER['SERVER_NAME'];
		$d = strstr($serverName, '.');
		$this->www = 'http://www' . $d;
		$this->admin = 'http://admin' . $d;
		$this->wap = 'http://wap' . $d;
		$this->api = 'http://api' . $d;
        $this->statistics = 'http://statistics' . $d;


        //get请求uri前缀
        $uri = '/api';
        $ak = '3PEmv6s3bEeco0mwpENonGsX';
        $sk = 'xYLfyN9dmFQgvxlKpf0DeBp8cdamULlB';
        $querystring_arrays = array (
            'v' => 2.0,
            'ak' => $ak,
        );
        $sn = $this->caculateAKSN($ak, $sk, $uri, $querystring_arrays);
        $this->baiduMap = 'http://api.map.baidu.com' . $uri . '?v=2.0&ak=' . $ak . '&sn=' . $sn;
	}

    private function caculateAKSN($ak, $sk, $url, $querystring_arrays, $method = 'GET') {
        if ($method === 'POST'){
            ksort($querystring_arrays);
        }
        $querystring = http_build_query($querystring_arrays);
        return md5(urlencode($url.'?'.$querystring.$sk));
    }

}